#include <stdio.h>
#include <stdlib.h>

/*
 * dynamically allocate two-dimensional array
 */
void alloc_dim2_arr (int col, int row)
{
    int i, j;
    int **arr = NULL;
    
    arr = (int**)malloc(col * sizeof(int*));

    for (i=0; i<col; i++) {
        arr[i] = (int*) malloc(row * sizeof(int));
        for (j=0; j<row; j++) {
            arr[i][j] = i*row +j;
            printf("arr[%d][%d]=%d\n", i, j, arr[i][j]);
        }
    }

    for (i=0; i<col; i++) {
        free(arr[i]);
    }
    
    free(arr);
    arr = NULL;
}

int main(int argc, char *argv[])
{
    alloc_dim2_arr(3, 4);
    
    return 0;
}

